package sf.r2dbc.sql;

import io.r2dbc.spi.Connection;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import sf.common.wrapper.Page;
import sf.core.DBObject;
import sf.dsl.DeleteDSL;
import sf.dsl.InsertDSL;
import sf.dsl.UpdateDSL;
import sf.dsl.example.Example;

import java.util.List;
import java.util.Map;

/**
 * 按example操作
 */
public interface R2dbcCrudExampleInf {
    /**
     * @param conn
     * @param start
     * @param limit
     * @param beanClass
     * @param example
     * @param <T>
     * @return
     */
    <T> Mono<Page<T>> selectPage(Connection conn, long start, int limit, Class<T> beanClass, Example example);

    /**
     * @param conn
     * @param example
     * @return
     * @
     */
    Mono<Object[]> selectArray(Connection conn, Example example);

    /**
     * @param conn
     * @param beanClass
     * @param example
     * @param <T>
     * @return
     */
    <T> Flux<T> selectList(Connection conn, Class<T> beanClass, Example example);

    /**
     * @param conn
     * @param beanClass
     * @param start
     * @param limit
     * @param example
     * @param <T>
     * @return
     */
    <T> Flux<T> selectList(Connection conn, Class<T> beanClass, long start, int limit, Example example);


    /**
     * @param conn
     * @param beanClass
     * @param example
     * @param <T>
     * @return
     */
    <T> Flux<T> selectListForUpdate(Connection conn, Class<T> beanClass, Example example);

    /**
     * @param conn
     * @param beanClass
     * @param example
     * @param <T>
     * @return
     * @
     */
    <T> Mono<T> selectOne(Connection conn, Class<T> beanClass, Example example);

    /**
     * @param conn
     * @param beanClass
     * @param example
     * @param <T>
     * @return
     */
    <T> Mono<T> selectOneForUpdate(Connection conn, Class<T> beanClass, Example example);

    /**
     * @param conn
     * @param example
     * @return
     * @
     */
    Flux<Map<String, Object>> select(Connection conn, Example example);

    /**
     * @param conn
     * @param insertDSL
     * @param datas     如果需要主键返回,可以放入一个空list
     * @return
     */
    Mono<Integer> insert(Connection conn, InsertDSL insertDSL, List<DBObject> datas);

    /**
     * @param conn
     * @param updateDSL
     * @return
     */
    Mono<Integer> update(Connection conn, UpdateDSL updateDSL);

    /**
     * @param conn
     * @param deleteDSL
     * @return
     */
    Mono<Integer> delete(Connection conn, DeleteDSL deleteDSL);
}
